class LightLabel extends egret.DisplayObjectContainer
{
    static gap = 8;
    public tiles: Tile[] = [];
    public index = 0;
    public time = 0;
    public constructor(text: string = "WINDSPIRIT")
    {
        super();
        var len = text.length;
        for(var i = 0;i < len;i++)
        {
            var tile = new Tile(text[i],colors[i % colors.length]);
            tile.x = i * (tile.width + LightLabel.gap) + (tile.width >> 1);
            this.addChild(tile);
            this.tiles.push(tile);
        }
        this.anchorX = 0.5;
        //this.delayLight();
    }
    public updateText(text)
    {
        var len = this.tiles.length;
        for(var i = 0;i < text.length;i++)
        {
            if(i < len)
            {
                this.tiles[i].label.text = text[i];
            }
            else
            {
                break;
            }
        }
    }
    public light()
    {
        var tile = this.tiles[this.index];
        tile.light();
        this.unlightPre();
        this.index++;
        this.index %= this.tiles.length;
        this.delayLight();
    }
    public get color()
    {
        return colors[(this.index - 1) % colors.length];
    }
    public delayLight()
    {
        var time = 480;
        this.time = setTimeout(this.light.bind(this),time);
    }
    public unlightPre()
    {
        var index = this.index - 2;
        if(index < 0)
        {
            index = this.tiles.length + index;
        }
        this.tiles[index].unlight();
    }
    public stop()
    {
        clearTimeout(this.time);
    }
}